require 'cache'

FormatFunctions = {
    'title' => [ /<div id=\"tn15title\">\s*<h1>&#34;([^<]*)&#34;.*<span>.*<\/h1>\s*<\/div>/, nil ],
    #'user rating' => [ /<b>(\d\d?\.?\d?)\/10<\/b>/, nil ],
    #'creator' => [ /<h5>Creator:<\/h5>\s(<a href="[^\"]*">[^<]*<\/a>)/, /<[^>]*>([^<]*)<\/a>/ ],
    #'seasons' => [ /<h5>Seasons:<\/h5>\s*((<a hre[^>]*>[^<]*<[^>]*>[ |\s]*)*)/, /<[^>]*>\s*([^<]*)<\/a>/ ],
    #'release date' => [ /<h5>Release Date:<\/h5>\s*([^<a]*)/, nil ],
    #'genre' => [ /<h5>Genre:<\/h5>\s*((<a href="[^"]*">[^<]*<\/a>[\s| ]*)*)/, /<[^>]*>\s*([^<]*)<\/a>/ ],
    #'tagline' => [ /<h5>Tagline:<\/h5>\s*([^<]*)/, nil ],
    #'plot' => [ /<h5>Plot:<\/h5>\s*([^<]*)/, nil ],
    #'plot keywords' => [ /<h5>Plot Keywords:<\/h5>\s<[^>]*><[^>]*>\s*((<a[^>]*>[^<]*<\/a>[\s| ]*)*)/, /<[^>]*>([^<]*)<\/a>/ ],
    #'runtine' => [ /<h5>Runtime:<\/h5>\s*([^<]*)/, nil ],
    #'country' => [ /<h5>Country:<\/h5>\s*((<a[^>]*>[^<]*<\/a>[\s| ]*)*)/, /<[^>]*>\s*([^<]*)<\/a>/ ],
    #'language' => [ /<h5>Language:<\/h5>\s*((<a[^>]*>[^<]*<\/a>[\s| ]*)*)/, /<[^>]*>\s*([^<]*)<\/a>/ ],
    #'color' => [ /<h5>Color:<\/h5>\s*((<a[^>]*>[^<]*<\/a>)*)/, /<[^>]*>\s*([^<]*)<\/a>/ ],
    #'sound mix' => [ /<h5>Sound Mix:<\/h5>\s*((<a[^>]*>[^<]*<\/a>)*)/, /<[^>]*>\s*([^<]*)<\/a>/ ]
    #'cast' => [ /(<table class=\"cast\">.*<\/table>)/, /<td class="nm"><a[^>]*>([^<]*)<\/a><\/td>/ ]
    #'awards' => [ /<h5>Awards:<\/h5>\s*([^<]*)/, nil ]
    #'company' => [ /<h5>Company:<\/h5>\s*<[^>]*>([^<]*)/, nil ]

    # photos
    # also known as
    # aspect ratio
    # certification
    # filming locations
    # movie meter
    }

FormatFunctions.each_pair do |key,value|
    # Match first group and assign to section.
    section = $data[value[0]][$1].strip
    # Skip if not found.
    if section != nil then
        $values[key] = (if value[1] == nil then [ section ] else section.scan(value[1]) end)
    end
end

$values.each_pair do |key,values|
    print "#{key}\n"
    values.each do |value|
        print "#{value}\n"
    end
    print "\n"
end
